package com.fourthdimension.jpa.common;

import org.springframework.util.StringUtils;

import javax.persistence.criteria.JoinType;

/**
 * @author ruiMin
 * @date 2020/2/15 16:20
 */
public class JoinUtil {

    public static final int PROP_SIZE = 2;

    public static JoinEntity getJoinEntity(String property) {
        JoinEntity joinEntity = new JoinEntity();
        String[] innerProperties = StringUtils.split(property, JoinEntity.INNER);
        if (innerProperties != null && innerProperties.length == PROP_SIZE) {
            joinEntity.setProperties(innerProperties);
            joinEntity.setJoinType(JoinType.INNER);
            return joinEntity;
        }
        String[] leftProperties = StringUtils.split(property, JoinEntity.LEFT);
        if (leftProperties != null && leftProperties.length == PROP_SIZE) {
            joinEntity.setProperties(leftProperties);
            joinEntity.setJoinType(JoinType.LEFT);
            return joinEntity;
        }
        joinEntity.setProperty(property);
        return joinEntity;
    }


}
